package cn.tedu._04mybatis.mapper;


import cn.tedu._04mybatis.pojo.entity.Weibo;
import cn.tedu._04mybatis.pojo.vo.WeiboVO1;
import cn.tedu._04mybatis.pojo.vo.WeiboVO2;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WeiboMapper {

    @Insert("INSERT INTO weibo(content,created,user_id) VALUES (#{content},#{created},#{userId})")
    int insert(Weibo weibo);

    @Delete("DELETE FROM weibo WHERE user_id= #{id}")
    int delete(Long id);

    @Update("UPDATE weibo SET content=#{content},created=#{created},user_id=#{userId} WHERE id = #{id}")
    int update(Weibo weibo);

    @Select("SELECT id,content,created,user_id as userId FROM weibo WHERE id=#{id}")
    Weibo select(Long id);

    @Select("SELECT id,content,created,user_id as userId FROM weibo WHERE user_id=#{userId}")
    List<Weibo> selectAll(Long uid);

    @Select("SELECT content,created FROM weibo WHERE id=#{id}")
    WeiboVO1 selectSomeVO1(Long id);

    @Select("SELECT w.content,w.created,u.nickname FROM user u JOIN weibo w ON w.user_id = u.id WHERE u.id = #{uid}")
    List<WeiboVO2> selectSomeVO2(Long uid);
}
